package com.fjp.heartguard.app.weight

import android.content.Context
import android.util.AttributeSet
import android.view.MotionEvent
import androidx.viewpager.widget.ViewPager

/**
 *Author:Mr'x
 *Time:2025/1/19
 *Description:
 */
class NoScrollViewPager : ViewPager {
    companion object {
        private const val TAG = "NoScrollViewPager"
    }

    private var isScrollAllowed = false

    constructor(context: Context?) : super(context!!) {}
    constructor(context: Context?, attrs: AttributeSet?) : super(context!!, attrs) {
    }

    override fun onTouchEvent(event: MotionEvent): Boolean {
        return if (isScrollAllowed) {
            super.onTouchEvent(event)
        } else false
    }

    override fun onInterceptTouchEvent(event: MotionEvent): Boolean {
        return if (isScrollAllowed) {
            super.onInterceptTouchEvent(event)
        } else false
    }

    fun setScrollAllowed(scrollAllowed: Boolean) {
        isScrollAllowed = scrollAllowed
    }
}